Leaflet Map with EJ Data

Show the code
library(sf)
Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
Show the code
library(leaflet)
library(terra)
terra 1.8.15
Show the code
# Load spatial EJ data
ej_data_sp <- read_sf('data/ej_cases/ej_data_public.gpkg')

# Load biodiversity data
biodiv <- rast('data/important_biodiversity_areas/minshort_speciestargetswithPA_esh10km_repruns10_ranked.tif')

# Define robin projection
robin <- "+proj=robin +lon_0=0 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs"

# Transform to Robinson projection
ej_data_sp_robin <- sf::st_transform(ej_data_sp, crs = robin)
biodiv_robin <- project(biodiv, robin)

# Create a leaflet map
leaflet() |>
  addTiles() |>
  addRasterImage(biodiv_robin) |>
  addMarkers(data = ej_data_sp_robin)
Warning: sf layer is not long-lat data
Warning: Point outside of projection domain (GDAL error 1)
Warning: Point outside of projection domain (GDAL error 1)
Warning: Point outside of projection domain (GDAL error 1)
Warning: Point outside of projection domain (GDAL error 1)